package com.huike.demo;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.huike.demo.pojo.ExcelData;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Test0 {
    public static void main(String[] args) {
        EasyExcel.write("G:\\系统默认\\桌面\\用户数据表_副本.xlsx")
                .head(ExcelData.class)
                .sheet("用户数据表")
                .doWrite(parseData());
    }

    private static List<ExcelData> parseData() {
        List<ExcelData> list = new LinkedList<>();
        EasyExcel.read("G:\\系统默认\\桌面\\用户数据表.xlsx")
                .head(ExcelData.class)
                .sheet()
                .registerReadListener(new AnalysisEventListener<ExcelData>() {
                    @Override
                    public void invoke(ExcelData excelData, AnalysisContext analysisContext) {
                        list.add(excelData);
                    }

                    @Override
                    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
                        System.out.println("数据读取完毕！！！");
                    }
                }).doRead();
        return list;
        //list.forEach(System.out::println);
        //list.forEach(map -> {
        //    Set<Map.Entry<Integer, String>> entries = map.entrySet();
        //    entries.forEach(entrySet-> System.out.print(entrySet.getKey()+":"+entrySet.getValue()+","));
        //    System.out.println("");
        //});
    }
}
